//
//  PasswordViewController.swift
//  BellManage
//
//  Created by Bestsch on 16/3/30.
//  Copyright © 2016年 wsl. All rights reserved.
//

import UIKit

class PasswordViewController: BaseViewController {

    var label1: UILabel!
    var label2: UILabel!
    var password1: FUITextField!
    var password2: FUITextField!
    var nextBT: FUIButton!
    
    var password: String!
    
    var phoneNum: String!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.title = "注册"
        
        initViews()

        
    }

    /**
     初始化视图控件
     
     - returns:
     */
    func initViews(){
        label1 = UILabel.init(frame: CGRect(x: 20, y: 90, width: screenW - 40, height: 30))
        label1.font = UIFont.systemFont(ofSize: 16)
        label1.textAlignment = NSTextAlignment.left
        label1.textColor = textlight
        label1.text = "设置密码"
        
        password1 = FUITextField.init(frame: CGRect(x: 20, y: label1.frame.maxY, width: screenW-40, height: 40))
        password1.backgroundColor = UIColor.clear
        password1.font = UIFont.systemFont(ofSize: 16)
        password1.edgeInsets = UIEdgeInsetsMake(0.0, 15.0, 0.0, 15.0)
        password1.textFieldColor = UIColor.white
        password1.layer.borderColor = UIColor.init(hexString: "f2f2f2", alpha: 1.0).cgColor
        password1.layer.borderWidth = 1.0
        password1.layer.cornerRadius = 3.0
        password1.borderColor = barColor
        password1.borderWidth = 2.0
        password1.cornerRadius = 3.0
        password1.placeholder = "请输入6位以上密码"
        password1.isSecureTextEntry = true
        
        label2 = UILabel.init(frame: CGRect(x: 20, y: password1.frame.maxY, width: screenW-40, height: 30))
        label2.font = UIFont.systemFont(ofSize: 16)
        label2.textAlignment = NSTextAlignment.left
        label2.textColor = textlight
        label2.text = "确认密码"
        
        password2 = FUITextField.init(frame: CGRect(x: 20, y: label2.frame.maxY, width: screenW-40, height: 40))
        password2.backgroundColor = UIColor.clear
        password2.font = UIFont.systemFont(ofSize: 16)
        password2.edgeInsets = UIEdgeInsetsMake(0.0, 15.0, 0.0, 15.0)
        password2.textFieldColor = UIColor.white
        password2.layer.borderColor = UIColor.init(hexString: "f2f2f2", alpha: 1.0).cgColor
        password2.layer.borderWidth = 1.0
        password2.layer.cornerRadius = 3.0
        password2.borderColor = barColor
        password2.borderWidth = 2.0
        password2.cornerRadius = 3.0
        password2.placeholder = "请再次输入密码"
        password2.isSecureTextEntry = true
        
        nextBT = FUIButton.init(frame: CGRect(x: 20, y: password2.frame.maxY+10, width: screenW - 40, height: 40))
        nextBT.buttonColor = barColor
        nextBT.shadowColor = barColor;
        nextBT.shadowHeight = 3.0
        nextBT.cornerRadius = 6.0
        nextBT.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        nextBT.setTitle("下一步", for: UIControlState())
        nextBT.setTitleColor(UIColor.white, for: UIControlState())
        nextBT.setTitleColor(UIColor.white, for: UIControlState.highlighted)
        nextBT.addTarget(self, action: #selector(PasswordViewController.nextBTClick), for: UIControlEvents.touchDown)
        
        self.view.addSubview(label1)
        self.view.addSubview(label2)
        self.view.addSubview(password1)
        self.view.addSubview(password2)
        self.view.addSubview(nextBT)
        
    }
    
    func nextBTClick(){
        
        password1.resignFirstResponder()
        password2.resignFirstResponder()
        
        password = password1.text
        if password.characters.count >= 6 {
            if password2.text == password {
                let codeVC = CodeViewController()
                codeVC.phoneNum = phoneNum
                codeVC.password = password
                self.navigationController?.pushViewController(codeVC, animated: true)
            }else{
                TSMessage.showNotification(in: self, title: "提示", subtitle: "对不清，您输入的密码两次不一样，请重新输入!", image: nil, type: TSMessageNotificationType.error, duration: 2.0, callback: nil, buttonTitle: "知道了", buttonCallback: nil, at: TSMessageNotificationPosition.top, canBeDismissedByUser: true)
                TSMessage.addCustomDesignFromFile(withName: "TSMessagesDefaultDesign.json")
            }
        }else{
            TSMessage.showNotification(in: self, title: "提示", subtitle: "为了您的信息安全，请输入6位以上的密码!", image: nil, type: TSMessageNotificationType.warning, duration: 2.0, callback: nil, buttonTitle: "知道了", buttonCallback: nil, at: TSMessageNotificationPosition.top, canBeDismissedByUser: true)
            TSMessage.addCustomDesignFromFile(withName: "TSMessagesDefaultDesign.json")
        }
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        password1.resignFirstResponder()
        password2.resignFirstResponder()
    }

    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
